<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户等级</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" th:href="@{/favicon.ico}" type="image/x-icon" />
    <link rel="stylesheet" th:href="@{/X-Admin/css/font.css}">
    <link rel="stylesheet" th:href="@{/X-Admin/css/xadmin.css}">
    <link rel="stylesheet" th:href="@{https://cdn.bootcss.com/Swiper/3.4.2/css/swiper.min.css}">
    <script type="text/javascript" th:src="@{https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{https://cdn.bootcss.com/Swiper/3.4.2/js/swiper.jquery.min.js}"></script>
    <script th:src="@{/X-Admin/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/X-Admin/js/xadmin.js}"></script>

</head>
<body>
<!-- 顶部开始 -->
<div th:replace="~{/commons/commons::topbar}"/>
<!-- 顶部结束 -->
<!-- 中部开始 -->
<div class="wrapper">
    <!-- 左侧菜单开始 -->
    <div th:replace="~{/commons/commons::leftbar}"/>
    <!-- 左侧菜单结束 -->
    <!-- 右侧主体开始 -->
        <div class="page-content">
          <div class="content">
            <!-- 右侧内容框架，更改从这里开始 -->
            <form class="layui-form xbs" action="" >

                <div class="layui-form-pane" style="text-align: center;display: none">
                  <div class="layui-form-item" style="display: inline-block;">
                    <label class="layui-form-label xbs768">日期范围</label>
                    <div class="layui-input-inline xbs768">
                      <input class="layui-input" placeholder="开始日" id="LAY_demorange_s">
                    </div>
                    <div class="layui-input-inline xbs768">
                      <input class="layui-input" placeholder="截止日" id="LAY_demorange_e">
                    </div>
                    <div class="layui-input-inline">
                      <input type="text" name="username"  placeholder="请输入用户名" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-input-inline" style="width:80px">
                        <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                    </div>
                  </div>
                </div>

            </form>
            <xblock><button class="layui-btn" onclick="level_add('添加用户等级','/level_add','','600','300')"><i class="layui-icon">&#xe608;</i>添加</button></xblock>
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>
                            ID
                        </th>
                        <th>
                            等级
                        </th>
                        <th>
                            修改日期
                        </th>
                        <th>
                            修改等级
                        </th>
                        <th>
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr th:each="level:${allLevels}">
                        <td th:text="${level.id}"></td>
                        <td th:text="${level.levelName}"></td>

                        <td th:text="${#dates.format(level.dateModified,'yyyy-MM-dd')}"></td>
                            <td class="layui-form">
                                <select name="levelName" class="layui-form-select">
                                    <option disabled>---请选择---</option>
                                    <option value="青铜">青铜</option>
                                    <option value="白银">白银</option>
                                    <option value="黄金">黄金</option>
                                    <option value="铂金">铂金</option>
                                    <option value="钻石">钻石</option>
                                    <option value="王者">王者</option>
                                    <option value="传奇">传奇</option>
                                    <option value="荣耀">荣耀</option>
                                    <option value="百星">百星</option>
                                </select>
                            </td>

                        <td class="td-manage">
                            <a title="确认" href="javascript:;" th:onclick="level_edit(this,'[[${level.id}]]')"
                            style="text-decoration:none">
                                <i class="layui-icon">&#xe605;</i>
                            </a>
                            <a title="删除" href="javascript:;" th:onclick="level_del(this,'[[${level.id}]]')"
                            style="text-decoration:none">
                                <i class="layui-icon">&#xe640;</i>
                            </a>
                        </td>
                    </tr>
                </tbody>
            </table>
            <!-- 右侧内容框架，更改从这里结束 -->
          </div>
        </div>
        <!-- 右侧主体结束 -->
    </div>
    <!-- 中部结束 -->
<!-- 底部开始 -->
<div th:replace="~{/commons/commons::footerbar}">
</div>
<!-- 底部结束 -->
<!-- 背景切换开始 -->
<div th:replace="~{/commons/commons::bgchange}">
</div>
<!-- 背景切换结束 -->
    <!-- 页面动态效果 -->
    <script>

        layui.use(['laydate'], function(){
          laydate = layui.laydate;//日期插件

          //以上模块根据需要引入
          //
          

          
          var start = {
            min: laydate.now()
            ,max: '2099-06-16 23:59:59'
            ,istoday: false
            ,choose: function(datas){
              end.min = datas; //开始日选好后，重置结束日的最小日期
              end.start = datas //将结束日的初始值设定为开始日
            }
          };
          
          var end = {
            min: laydate.now()
            ,max: '2099-06-16 23:59:59'
            ,istoday: false
            ,choose: function(datas){
              start.max = datas; //结束日选好后，重置开始日的最大日期
            }
          };
          
          document.getElementById('LAY_demorange_s').onclick = function(){
            start.elem = this;
            laydate(start);
          }
          document.getElementById('LAY_demorange_e').onclick = function(){
            end.elem = this
            laydate(end);
          }
          
        });

        //批量删除提交
             function delAll () {
                layer.confirm('确认要删除吗？',function(index){
                    //捉到所有被选中的，发异步进行删除
                    layer.msg('删除成功', {icon: 1});
                });
             }
            // 等级-增加
            function level_add (title,url,id,w,h) {
                x_admin_show(title,url,w,h); 
            }
            // 等级-编辑
            function level_edit (obj,id) {
                let options=$(obj).parent().parent().find("td").eq(3);
                let levelName=options.find("option:selected").val();

                let date=new Date();

                let year=date.getFullYear();
                let month=date.getMonth()+1;
                let date1=date.getDate();
                month=month<=9?'0'+month:month;
                date1=date1<=9?'0'+date1:date1;
                let dateModified=year+"-"+month+"-"+date1;

                layer.confirm('确认要修改吗？',function(index){
                    $.ajax({
                        url: "/levelUpdate",
                        isAysn: false,
                        type: 'get',
                        contentType: 'application/json',
                        data: {id,levelName}
                    });
                    let option=$(obj).parent().parent().find("td").eq(1);
                    let newDate=$(obj).parent().parent().find("td").eq(2);
                    option.text(levelName);
                    newDate.text(dateModified);
                    layer.msg('已修改!',{icon:1,time:1000});
                });
            }
           
            /*等级-删除*/
            function level_del(obj,id){
                layer.confirm('确认要删除吗？',function(index){
                    //发异步删除数据
                    $.ajax({
                        url: "/levelDelete",
                        isAysn: false,
                        type: 'get',
                        contentType: 'application/json',
                        data: {id}
                    });
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                });
            }
        </script>
        <script>
        //百度统计可去掉
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
          var s = document.getElementsByTagName("script")[0]; 
          s.parentNode.insertBefore(hm, s);
        })();
        </script>
</body>
</html>